<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  var arr = function (directions) {
    //去掉开始的'L'
    while (directions[0] == 'L') {
      directions = directions.slice(1)
    }
    //去掉结尾的'R'
    while (directions[directions.length - 1] == 'R') {
      directions = directions.slice(0, directions.length - 1)
    }
    //去掉'S'
    directions = directions.replaceAll('S', '')
    return directions.length
  };
  console.log(arr(directions = "RLRSLL"));
</script>

</html>